<?php
// +----------------------------------------------------------------------------
// | Tke团队版权所属 [三十年河东三十年河西,莫欺少年穷.!]
// +----------------------------------------------------------------------------
// | Copyright (c) 2014 http://www.itdaodan.com All rights reserved.
// +----------------------------------------------------------------------------
// | Author: PHP@妖孽 <dino_ma@163.com>
// +----------------------------------------------------------------------------
namespace Admin\Service;
/**
 * @todo 用户服务层
 * @author PHP@妖孽 <dino_ma@163.com>
 * @since 2015-8-17
 */
class CustomerService{
	
	 protected $error	 =   '';
	
		/**
		 * @todo 通过手机号返回用户信息(单条) cache 1小时
		 * @param mobile_phone string  手机号
		 * @param filed		string 字段
		 * return array();
		 * @author PHP@妖孽 <dino_ma@163.com>
		 */
		public function getCustomerByMobilePhone($mobile_phone,$field){
			return D('Admin/Customer')->getCustomerByMobilePhone($mobile_phone,$field);
		}
	 
	 
		/**
		 * @todo 通过Uid返回用户信息(单条) cache 1小时
		 * @param customer_id array/int  用户Id 1,2,3
		 * @param filed		string 字段
		 * return array();
		 * @author PHP@妖孽 <dino_ma@163.com>
		 */
		public function getCustomerByCustomerId($customer_id,$field){
			return D('Admin/Customer')->getCustomerByCustomerId($customer_id,$field);
		}
	 	
		/**
		 * @todo 查看用户是否报名
		 * @param activity_id int 活动id
		 * @param customer  int or string  支持用户id或手机号
		 */
		public function customerIsJoinActivity($activity_id,$customer,$sign_channel,$ticket_level){
			$obj = D('Admin/Customer');
			if($customer_id = $obj->customerIsJoinActivity($activity_id,$customer,$sign_channel,$ticket_level)){
				return $customer_id;
			}else{
				$this->error = $obj->getError();
				return false;
			}
// 			return D('Admin/Customer')->customerIsJoinActivity($activity_id,$customer);
		}
		
		
		/**
		 * @todo 通过用户手机号获取用户id
		 * @param string(11) mobile_phone 手机号
		 * @author PHP@妖孽 <dino_ma@163.com>
		 */
		public function getCustomerIdByMobilePhone($mobile_phone){
			$obj = D('Admin/Customer');
			$call_back = $obj->getCustomerIdByMobilePhone($mobile_phone);
			return $call_back;
		}
		
		
		/**
	     * @todo 验证用户id是否存在
	     * @param int(11) customer_id 用户id
	     * @author PHP@妖孽 <dino_ma@163.com>
	     */
	    public function checkCustomerIdIsTrue($customer_id){
			$obj = D('Admin/Customer');
			if($customer_id = $obj->checkCustomerIdIsTrue($customer_id)){
				return $customer_id;
			}else{
				$this->error = $obj->getError();
				return false;
			}
		}
		
		
		
		
		
		/**
		 * @todo 注册一个用户返回uid
		 * @param string(11) login_name 手机号
		 * @param string(18) login_pwd 密码（暂时为空）
		 * @param string(11) mobile_phone 手机号
		 * @param string(1-3) customer_name 用户姓名（可为空）
		 * @param int reg_type //1:后台代报名,2:后台资源导入,3:安卓注册,4:IPhone注册,5:Ipad注册,6:网站注册,7:活动报名,8:收款进入
		 * @author PHP@妖孽<dino_ma@163.com>
		 */
		public function register($login_name,$login_pwd,$mobile_phone,$customer_name,$reg_type){
			$obj = D('Admin/Customer');
			if($customer_id = $obj->register($login_name,$login_pwd,$mobile_phone,$customer_name,$reg_type)){
				return $customer_id;
			}else{
				$this->error = $obj->getError();
				return false;
			}
		}
		
		
		/**
		 * @todo 返回最后一次错误记录
		 * @return string
		 * @author PHP@妖孽 <dino_ma@163.com>
		 */
		public function getError(){
			return $this->error;
		}
}
